include ../../tools/makedefaults.inc

INCLUDES = -I../inc
PRINTFOP = -Wl,-u,vfprintf -lprintf_min
LDFLAGS = $(PRINTFOP) 

BNAME = ../../bin/hboot
BHEX = $(BNAME).hex
BELF = $(BNAME).elf

vpath %.c = ../drivers \
						../drivers/devices \
						../hal

# Bootloader Source Files
SRC = 	hboot.c \
			at45db011.c \
			lcd.c \
			uart.c \
			spi.c \
			io.c \

# Bootloader object files
OBJ = $(SRC:.c=.o)

all: $(BHEX) size

%.o: %.c
	@echo " - Compiling $@"
	@$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

$(BELF): $(OBJ)
	@echo " - Linking $@"
	@$(CC) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS) -Wl,--section-start=.text=0x1E000

%.hex: %.elf
	@echo " - Generating hex file $@"
	@$(OBJCOPY) -S -O ihex -R .eeprom $< $@

size: $(OSELF)
	@/bin/echo -n " - Boot Size "
	@../../tools/avr-mem.sh $(BELF) $(MCU)

clean:
	@echo " - Cleaning objects"
	@rm -f $(OBJ) $(BELF) $(BHEX)
